"""
本代码由[Tkinter布局助手]生成
官网:https://www.pytk.net
QQ交流群:788392508
"""
from tkinter import *
from tkinter.ttk import *
from address_book_modify import org_member_modify, org_code_modify
from comparison_of_results import compare_json


class WinGUI(Tk):
    def __init__(self):
        super().__init__()
        self.__win()
        self.tk_tabs_lpkykkt8 = self.__tk_tabs_lpkykkt8(self)
        self.tk_button_lpkymoq2 = self.__tk_button_lpkymoq2(self.tk_tabs_lpkykkt8_0)
        self.tk_button_lpkyogmu = self.__tk_button_lpkyogmu(self.tk_tabs_lpkykkt8_0)
        self.tk_label_lpkz05k7 = self.__tk_label_lpkz05k7(self.tk_tabs_lpkykkt8_0)
        self.tk_button_lpkz2o51 = self.__tk_button_lpkz2o51(self.tk_tabs_lpkykkt8_1)
        self.tk_label_lpkz2zzq = self.__tk_label_lpkz2zzq(self.tk_tabs_lpkykkt8_1)
        self.tk_label_lpkz4lju = self.__tk_label_lpkz4lju(self.tk_tabs_lpkykkt8_1)
        self.tk_label_lpkz4wi8 = self.__tk_label_lpkz4wi8(self.tk_tabs_lpkykkt8_1)

    def __win(self):
        self.title("Tkinter布局助手")
        # 设置窗口大小、居中
        width = 600
        height = 300
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)

        self.resizable(width=False, height=False)

    def scrollbar_autohide(self, vbar, hbar, widget):
        """自动隐藏滚动条"""

        def show():
            if vbar: vbar.lift(widget)
            if hbar: hbar.lift(widget)

        def hide():
            if vbar: vbar.lower(widget)
            if hbar: hbar.lower(widget)

        hide()
        widget.bind("<Enter>", lambda e: show())
        if vbar: vbar.bind("<Enter>", lambda e: show())
        if vbar: vbar.bind("<Leave>", lambda e: hide())
        if hbar: hbar.bind("<Enter>", lambda e: show())
        if hbar: hbar.bind("<Leave>", lambda e: hide())
        widget.bind("<Leave>", lambda e: hide())

    def v_scrollbar(self, vbar, widget, x, y, w, h, pw, ph):
        widget.configure(yscrollcommand=vbar.set)
        vbar.config(command=widget.yview)
        vbar.place(relx=(w + x) / pw, rely=y / ph, relheight=h / ph, anchor='ne')

    def h_scrollbar(self, hbar, widget, x, y, w, h, pw, ph):
        widget.configure(xscrollcommand=hbar.set)
        hbar.config(command=widget.xview)
        hbar.place(relx=x / pw, rely=(y + h) / ph, relwidth=w / pw, anchor='sw')

    def create_bar(self, master, widget, is_vbar, is_hbar, x, y, w, h, pw, ph):
        vbar, hbar = None, None
        if is_vbar:
            vbar = Scrollbar(master)
            self.v_scrollbar(vbar, widget, x, y, w, h, pw, ph)
        if is_hbar:
            hbar = Scrollbar(master, orient="horizontal")
            self.h_scrollbar(hbar, widget, x, y, w, h, pw, ph)
        self.scrollbar_autohide(vbar, hbar, widget)

    def __tk_tabs_lpkykkt8(self, parent):
        frame = Notebook(parent)
        self.tk_tabs_lpkykkt8_0 = self.__tk_frame_lpkykkt8_0(frame)
        frame.add(self.tk_tabs_lpkykkt8_0, text="通讯录获取")
        self.tk_tabs_lpkykkt8_1 = self.__tk_frame_lpkykkt8_1(frame)
        frame.add(self.tk_tabs_lpkykkt8_1, text="数据比对")
        frame.place(x=0, y=0, width=600, height=500)
        return frame

    def __tk_frame_lpkykkt8_0(self, parent):
        frame = Frame(parent)
        frame.place(x=0, y=0, width=600, height=500)
        return frame

    def __tk_frame_lpkykkt8_1(self, parent):
        frame = Frame(parent)
        frame.place(x=0, y=0, width=600, height=500)
        return frame

    def __tk_button_lpkymoq2(self, parent):
        btn = Button(parent, text="获取组织列表", takefocus=False, )
        btn.place(x=90, y=20, width=150, height=60)
        return btn

    def __tk_button_lpkyogmu(self, parent):
        btn = Button(parent, text="获取人员列表", takefocus=False, )
        btn.place(x=350, y=20, width=150, height=60)
        return btn

    def __tk_label_lpkz05k7(self, parent):
        label = Label(parent, text="", anchor="center", )
        label.place(x=0, y=130, width=600, height=346)
        return label

    def __tk_button_lpkz2o51(self, parent):
        btn = Button(parent, text="按钮", takefocus=False, )
        btn.place(x=410, y=10, width=150, height=60)
        return btn

    def __tk_label_lpkz2zzq(self, parent):
        label = Label(parent, text="", anchor="center", )
        label.place(x=0, y=90, width=598, height=387)
        return label

    def __tk_label_lpkz4lju(self, parent):
        label = Label(parent, text="历史文件", anchor="center", )
        label.place(x=40, y=0, width=134, height=77)
        return label

    def __tk_label_lpkz4wi8(self, parent):
        label = Label(parent, text="新文件", anchor="center", )
        label.place(x=230, y=0, width=134, height=77)
        return label


class Win(WinGUI):
    def __init__(self):
        super().__init__()
        self.__event_bind()

    def button_org_code_modify(self, evt):
        """
        获取组织按钮点击事件
        :param evt:
        :return:
        """
        org_code_modify()

    def button_org_member_modify(self, evt):
        """
        获取人员按钮点击事件
        :param evt:
        :return:
        """
        org_member_modify()

    def button_comparison_of_results(self, evt):
        """
        比对文件内容点击事件
        :param evt:
        :return:
        """
        compare_json("2023-11-29组织列表.json", "2023-11-30组织列表.json")

    def __event_bind(self):
        self.tk_button_lpkymoq2.bind('<Button>', self.button_org_code_modify)
        self.tk_button_lpkyogmu.bind('<Button>', self.button_org_member_modify)
        self.tk_button_lpkz2o51.bind('<Button>', self.button_comparison_of_results)
        pass


if __name__ == "__main__":
    win = Win()
    win.mainloop()
